<?php
/**
 * @package  nuo
 * @author   Nam Nguyen <nam.ngvan@gmail.com>
 * @version  1.0
 * @since    Apr 17, 2013
 */
class Nuo_Messenger
{

	/**
	 * @var Nuo_Messenger
	 */
	private static $_instance = NULL;

	/**
	 * Constant
	 */
	CONST SESSION_KEY = 'Nuo_Messenger';

	private function __construct()
	{
		// no code here
	}

	/**
	 * @access  public
	 * @param   string  $msg
	 * @return  Nuo_Messenger
	 */
	function add($msg)
	{
		$_SESSION[self::SESSION_KEY][] = $msg;
		return $this;
	}

	/**
	 * Get messenger
	 * @access  public
	 * @return  string
	 */
	function get()
	{
		if (isset($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY])
		{
			$msg = implode(PHP_EOL, $_SESSION[self::SESSION_KEY]);
			$_SESSION[self::SESSION_KEY] = array();
			return $msg;
		}
		return '';
	}

	/**
	 * Singleton method
	 * @static
	 * @access public
	 * @return Nuo_Messenger
	 */
	static function instance()
	{
		if (NULL == self::$_instance)
		{
			self::$_instance = new self;
		}
		return self::$_instance;

	}

}
